// Java控制台输出System.getProperties()所有属性及值

/**
 * @from www.everycoding.com
 * @Description:输出System.getProperties()所有属性及值
 */
public class ListWorkPropertiesTester {
    public static void main(String[] args) {
        Set<Entry> sets = System.getProperties().entrySet();
        for (Entrye : sets) {
            System.out.println("【key】:"+e.getKey()+"----->【value】:"+e.getValue());
        }
    }
}

// Java Properties属性存储到指定文件中的实例

/**
 * @from www.everycoding.com
 * @Description:Properties属性存储到指定文件中的实例
 */
public class PropertiesStore {
    public static void main(String[] args) throws IOException {
        Properties props = new Properties();
        URL url = ClassLoader.getSystemResource("com/properties/config.properties");
        props.load(url.openStream());
        String dir = ClassLoader.getSystemResource("com/properties/").getPath();
        props.store(new FileOutputStream(dir+"/target.properties"), "no comments");
        System.out.println("store path:"+dir+"/target.properties");
    }
}


// Java Properties从classpath读取文件内容并通过list方式输出

/**
 * @from www.everycoding.com
 * @Description:Properties读取文件和输出内容
 */
public class PropertiesRead {
    public static void main(String[] args) throws Exception {
        Properties p = new Properties();
        URL url = ClassLoader.getSystemResource("config.properties");
        p.load(url.openStream());
        // 输出文件内容
        p.list(System.out);
        // 打印Properties存储结构
        System.out.println("打印Properties存储结构："+p);
    }
}
// -- listing properties --
// china=中国
// 打印Properties存储结构：{china=中国}


Java Properties读取文件和输出内容

/**
 * @from www.everycoding.com
 * @Description:Properties读取文件和输出内容
 */
public class PropertiesRead {
    public static void main(String[] args) throws Exception {
        Properties p = new Properties();
        p.load(new FileInputStream("D:\\config.properties"));
        for (Object key : p.keySet()) {
            System.out.println("key:"+key+",value:"+p.getProperty(key.toString()));
        }
    }
}

public class PropertiesRead {
    public static void main(String[] args) throws Exception {
        Properties p = new Properties();
        URL url = ClassLoader.getSystemResource("config.properties");
        p.load(url.openStream());
        for (Object key : p.keySet()) {
            System.out.println("key:"+key+",value:"+p.getProperty(key.toString()));
        }
    }
}